package cn.itcast.stream;

import cn.itcast.entity.UserEntity;

import javax.jws.soap.SOAPBinding;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.function.Predicate;
import java.util.stream.Stream;

public class Test {
    public static void main(String[] args) {
        ArrayList<UserEntity> userEntities = new ArrayList<>();
        userEntities.add(new UserEntity("张三",18));
        userEntities.add(new UserEntity("李四",26));
        userEntities.add(new UserEntity("王二",10));
        userEntities.add(new UserEntity("麻子",28));
        userEntities.add(new UserEntity("孙悟空",7000));
        userEntities.add(new UserEntity("孙悟空",400));
        userEntities.add(new UserEntity("孙悟空",10000));
        userEntities.add(new UserEntity("唐生",200));
        userEntities.add(new UserEntity("八戒",3000));
        userEntities.add(new UserEntity("沙僧",456));

        Stream <UserEntity> stream = userEntities.stream();
        stream.sorted(new Comparator<UserEntity>() {
            @Override
            public int compare(UserEntity o1, UserEntity o2) {
                return o2.getAge() - o1.getAge();
            }
        }).filter(new Predicate<UserEntity>() {
            @Override
            public boolean test(UserEntity userEntity) {
                return "孙悟空".equals(userEntity.getName());
            }
        }).skip(1).limit(2).forEach(userEntity -> System.out.println(userEntity.toString()));

    }
}
